<?php
// +----------------------------------------------------------------------
// | WoShiMaiJia Projcet
// +----------------------------------------------------------------------
// | Copyright (c) 2010 http://woshimaijia.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: xinqiyang <517577550@qq.com>
// +----------------------------------------------------------------------


/**
 +------------------------------------------------------------------------------
 * AppBaseAction
 +------------------------------------------------------------------------------
 * @category
 * @package
 * @subpackage
 * @author   xinqiyang <517577550@qq.com>
 +------------------------------------------------------------------------------
 */
class AppBaseAction extends BaseAction
{

	/**
	 * 用户ID
	 */
	private $uid;
	private $uinfo;
	
	/**
	 * 访客ID
	 * @var unknown_type
	 */
	private $gid;
	//定义预处理函数
	protected function _bf_insert($fn) { }
	protected function _bf_update($fn) { }

	protected function _af_update($fn) { }
	protected function _af_insert($fn) { }

	protected function _bf_show($fn) { }

	/**
	 * Initialize function
	 */
	protected function _baseinit()
	{
		//检查状态,决定是否刷新session内容
		
		$uinfo = Session::get('uinfo');
		if($uinfo)
		{
			$this->assign('uinfo',$uinfo);
			$this->uinfo = $uinfo;
			$this->uid = $uinfo['id'];
			
		}

	}

	/**
	 * 获取当前用户的ID
	 */
	protected function getuid()
	{
		$uinfo = Session::get('uinfo');
		return $uinfo['id'];
	}

	/**
	 * 修改了用户信息
	 */
	protected function changeuinfo()
	{
		Session::set('uinfo',$this->getuserinfo($this->getuid()));
	}


	/**
	 * Get UserInfo
	 * 用户的信息调用
	 * @param $uid
	 * @param $simple
	 */
	protected function getuserinfo($uid)
	{
		$d = D('user');
		return $d->get('id='.$uid,'id,enname,cnname,image_id,havemail,locationid,microblog,score,status,city');
	}


	/**
	 * 设置页面公共信息
	 * TODO:需要改进调用页面信息
	 * @param unknown_type $info
	 */
	protected function setpageinfo($info=array())
	{
		//根据具体内容的不同而不同
		//设置网页公共信息  title keywords descript h1 等
		$this->assign('page',$page);
	}

//	/**
//	 * 模块调用入口
//	 * by xinqiyang
//	 */
//	public function _empty()
//	{
//		$this->show();
//	}
	/**
	 * show template
	 * use layout template
	 *
	 */
	protected function show()
	{
		if(method_exists($this,'_bf_show'))
		{
			$this->_bf_show(ACTION_NAME);
		}
		//显示具体的方法
		$this->t();
	}
	
	

	/**
	 * 返回URL
	 */
	public function getReturnUrl()
	{
		return __URL__.'?'.C('VAR_MODULE').'='.MODULE_NAME.'&'.C('VAR_ACTION').'='.C('DEFAULT_ACTION');
	}

	

}
?>